package com.fs.controller;

import com.fs.annotation.SysLog;
import com.fs.service.FileService;
import com.fs.vo.ImageVO;
import com.fs.vo.SysResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Api(tags = "文件上传控制器")
@RestController
@CrossOrigin
@RequestMapping("/file")
public class FileController {

    @Autowired
    private FileService fileService;

    /**
     * url:/file/upload
     *类型：post
     * 参数：
     * 返回值：
     */
    @SysLog("文件上传")
    @ApiOperation(value = "文件上传")
    @RequiresPermissions({"other:file:upload"})
    @PostMapping("/upload")
    public SysResult fileUpload(MultipartFile file){
        ImageVO imageVO = fileService.upload(file);
        return SysResult.success(imageVO);
    }

    /**
     *完成图片删除的操作
     * url：http://localhost:8095/file/deleteFile
     * 参数：virtualPath 虚拟路径
     * 类型：delete
     * 返回值：SysResult对象
     */
    @SysLog("文件删除")
    @ApiOperation(value = "文件删除")
    @RequiresPermissions({"other:file:del"})
    @DeleteMapping("/deleteFile")
    public SysResult deleteFile(String virtualPath){
        fileService.deleteFile(virtualPath);
        return SysResult.success();
    }

}
